<template>
    <view>
        <web-view 
            :src="getWebViewUrl()" 
            @message="onWebViewMessage"
        ></web-view>
    </view>
</template>

<script>
export default {
    data() {
        return {
            parentCoordinates: [119.2165147083665, 26.042732143393025] // 注意移除多余的逗号
        };
    },
    methods: {
        getWebViewUrl() {
            const coordinatesStr = this.parentCoordinates.join(',');
            return `/static/html/map-drawer.html?center=${encodeURIComponent(coordinatesStr)}`;
        },
        onWebViewMessage(e) {
            // ✅ 规范代码缩进和结构
            const message = e.detail.data[0];
            if (message && message.type === 'polygonCoordinates') {
                console.log('坐标数据:', message.data);
                this.parentCoordinates = message.data;
            }
        }
    }
};
</script>